package cosplay.Services;

import java.sql.Timestamp;

import cosplay.Beans.Competitions;
//return null if unavailable or initialized competition
public class CompetitionServices {
	public static Competitions CompetitionVerify(Competitions competition)
	{
		Timestamp now =new Timestamp(System.currentTimeMillis());
		if (competition.getDescription()==null)
			competition.setDescription("");
		if (competition.getJoinLimit()<=0)
			return null;
		if (competition.getName()==null)
			return null;
		if ((competition.getStartDate().before(now))||(competition.getStartDate()==null))
			competition.setActive(false);
		if ((competition.getEndDate().after(now))||(competition.getEndDate()==null))
			competition.setActive(false);
		if ((competition.getLastJoined().after(now))||(competition.getLastJoined()==null))
			competition.setLastJoined(null);
		if ((competition.getLastViewed().after(now))||(competition.getLastViewed()==null))
			competition.setLastViewed(null);
		if ((competition.getLastVoted().after(now))||(competition.getLastVoted()==null))
			competition.setLastVoted(null);
		return competition;
	}
}
